/*
** audiocore.h
** Audio core interface header
**
** Mathieu Garcia - mateo (at) bblk (dot) net
*/

#include <CoreFoundation/CoreFoundation.h>
#include <AudioToolbox/AudioQueue.h>
#include <sndfile.h>
#include <glib.h>

#define BUFFERS 3

/* Sample access and reference */
typedef struct audiosample_s
{
  SNDFILE	*sndfile;
  SF_INFO	*sndinfo;
  short		*buffer;
  unsigned long	size;
} audiosample_t;

/* Describe a sample currently played */
typedef struct samplesnapshot_s
{
  int		channels;
  unsigned int 	sample_type;
  short		*buffer;		/* Points to the begining of the original buffer*/
  short		*cur;			/* Current position in original buffer */
  short		*end;			/* Points to the last sample */
} samplesnapshot_t;

enum AudioCoreStatus
  {
    kAudioCoreStatusStopped,
    kAudioCoreStatusPlaying
  };

/* The audio callback structure */
typedef struct audio_cb_s
{
  AudioQueueRef					queue;
  UInt32					frameCount;
  AudioQueueBufferRef				buffers[BUFFERS];
  AudioStreamBasicDescription			dataFormat;
  GHashTable					*samples;
} audio_cb_t;

void	audiocore_cb(void *, AudioQueueRef, AudioQueueBufferRef);
void	*audiocore_thread(void *);
void	audiocore_stop();
int	audiocore_load_samples(audio_cb_t *);
